package com.bodu.system.controller;

import com.bodu.core.common.AbstractCommonController;
import com.bodu.core.entity.ParamReq;
import com.bodu.core.entity.result.PageResult;
import com.bodu.core.entity.result.Result;
import com.bodu.global.annon.TraceLog;
import com.bodu.global.security.LoginUserUtil;
import com.bodu.system.entity.request.RoleRequest;
import com.bodu.system.entity.vo.RoleVo;
import com.bodu.system.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author gaoya
 */
@Api(tags = "角色管理")
@RestController
@RequestMapping("/role")
public class RoleController extends AbstractCommonController<RoleService, RoleRequest, RoleVo> {

    private final RoleService roleService;

    public RoleController(RoleService roleService) {
        this.roleService = roleService;
    }

    @TraceLog()
    @ApiOperation("角色详情")
    @GetMapping
    public Result<RoleVo> getModel(Long id) {
        return super.getModel(roleService, id);
    }

    @TraceLog()
    @ApiOperation("保存角色")
    @PostMapping
    public Result save(@RequestBody RoleRequest roleRequest) {
        return super.save(roleService, roleRequest);
    }

    @TraceLog()
    @ApiOperation("更新角色")
    @PutMapping
    public Result update(@RequestBody RoleRequest roleRequest) {
        return super.update(roleService, roleRequest);
    }

    @TraceLog()
    @ApiOperation("角色列表")
    @PostMapping("listPage")
    public Result<List<RoleVo>> listPage(@RequestBody ParamReq<RoleRequest> req)  {
        return super.listPage(roleService, req);
    }

    @TraceLog()
    @ApiOperation("角色列表-统计")
    @PostMapping("countPage")
    public Result<Integer> countPage(@RequestBody ParamReq<RoleRequest> req)  {
        return super.countPage(roleService, req);
    }

    @TraceLog()
    @ApiOperation("角色列表-分页")
    @PostMapping("page")
    public Result<PageResult> page(@RequestBody ParamReq<RoleRequest> req)  {
        return super.page(roleService, req);
    }

    @TraceLog()
    @ApiOperation("角色列表-删除")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Long id) {
        return super.delete(roleService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除")
    @DeleteMapping("{ids}")
    public Result batchDelete(@PathVariable("ids")List<Long> ids) {
        return super.batchDelete(roleService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }
}
